package cn.t222.mapper;

import cn.t222.pojo.Product;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
public class ProductContollerTest {
    @Resource
    private ProductRepository porductRepository;
    private Integer PAGESIZE=10;
    static {
        System.setProperty("es.set.netty.runtime.available.processors","false");
    }
    @Test
    public void testAdd() {
        long id = System.currentTimeMillis();
        Product product = new Product(id,"红富士","水果", 7.99,"/img/p1.jpg","这是一个测试商品");
        porductRepository.save(product);
        System.out.println(product.getId());
    }
    @Test
    public void testAdd2() {
        long id = System.currentTimeMillis();
        List<Product> list = new ArrayList<>();
        list.add(new Product(id,"金帅","水果", 7.99,"/img/p1.jpg","金帅也和红富士一样，非常好吃，脆脆的"));
        list.add(new Product(id + 100,"苹果XS","手机", 4888.0,"/img/p2.jpg","这是一个手机"));
        list.add(new Product(id + 200,"红富士","水果", 7.99,"/img/p3.jpg","这是一个测试商品"));
        porductRepository.saveAll(list);
    }
    @Test
    public void getProductId() {
        Product product = porductRepository.findByName("富士");
        System.out.println(product);
    }

    @Test
    public void findByPrice() {
        List<Product> list = porductRepository.findByPriceBetween(7,8);
        list.forEach(product -> System.out.println(product));
    }
}
